package work.binarysearch;

public class Problem74 {
    public boolean searchMatrix(int[][] matrix, int target) {
        //行数
        int n = matrix.length;
        //列数
        int m = matrix[0].length;
        int left = 0, right = m * n - 1;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (matrix[mid / m][mid % m] > target) right = mid - 1;
            else if (matrix[mid / m][mid % m] < target) left = mid + 1;
            else return true;
        }
        return false;
    }
}
